package com.gonsin.gview.logic.utils;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;

import java.io.*;

import static cn.hutool.core.util.CharsetUtil.UTF_8;

public class MustacheUtils {

    /**
     * 用freemarker框架注入字符串
     */
    public static String generalString(String in, Object params) throws Exception {
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile(new StringReader(in), UTF_8);
        StringWriter writer = new StringWriter();
        mustache.execute(writer, params).flush();
        return writer.toString();
    }

}
